#include "common.h"
#include "thread_cache.h"
#include "ConcurrentAlloc.h"

void Alloc1()
{
	for (int i = 0; i < 5; i++)
	{
		pThreadCache->AllocMem(5);
	}
}

void Alloc2()
{
	for (int i = 0; i < 6; i++)
	{
		pThreadCache->AllocMem(5);
	}
}

void testTsl()
{
	std::thread t1(Alloc1);
	std::thread t2(Alloc2);
	t1.join();
	t2.join();
}

void testConCurrentAlloc()
{/*
	void* p1 = ConcurrentAlloc(5);
	void* p2 = ConcurrentAlloc(6);
	void* p3 = ConcurrentAlloc(7);
	void* p4 = ConcurrentAlloc(8);*/

	for (int i = 0; i < 1024; i++)
	{
		void* p5 = ConcurrentAlloc(5);
	}

	void* p6 = ConcurrentAlloc(8);
	void* p7 = ConcurrentAlloc(8);
}

void AllocFree1()
{
	std::vector<void*> v;
	for (int i = 0; i < 7; i++)
	{
		void* p = ConcurrentAlloc(7);
		v.push_back(p);
	}

	for (int i = 0; i < 6; i++)
	{
		ConcurrentDel(v[i]);
	}
	ConcurrentDel(v[6]);

}

void AllocFree2()
{
	std::vector<void*> v;
	for (int i = 0; i < 9; i++)
	{
		void* p = ConcurrentAlloc(7);
		v.push_back(p);
	}
	for (auto& e : v)
	{
		ConcurrentDel(e);
	}
}

void testAllocFree()
{
	std::thread t1(AllocFree1);
	std::thread t2(AllocFree2);
	t1.join();
	t2.join();
}

void testBigAlloc()
{
	void* p = ConcurrentAlloc(257 * 1024);
	void* p1 = ConcurrentAlloc(129 * 8 * 1024);
	ConcurrentDel(p);
	ConcurrentDel(p1);
}

int main1()
{
	//testTsl();

	//testConCurrentAlloc();

	//testAllocFree();

	testBigAlloc();
	return 0;
}